/**
 * Created by meiguizhinian on 2018/6/22
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

ivy.SceneCommonDataManager = {
	getInstance : function () {
		return this;
	},

	initWithFile : function (filename) {
		let is = new ivy.InputStream(filename);
		cc.assert(!is.empty(), "读取文件失败"+filename);
		this._systemFaceAniID = is.readJInt16();
		this._dialogHeadAniID = is.readJInt16();
		this._equipIconAniID = is.readJInt16();
		this._effectAniID = is.readJInt16();

		this._actorClassCount = is.readJInt16();
		this._isActorPackAni = [];
		this._actorResType = [];
		this._classAIIDs = [];
		this._classFlags = [];
		this._aniFileName = [];
		for (let i = 0; i < this._actorClassCount; ++i) {
			this._isActorPackAni[i] = is.readBool();
			this._actorResType[i] = is.readInt8();
			this._classAIIDs[i] = is.readInt8();
			this._classFlags[i] = is.readInt8();
			this._aniFileName[i] = is.readStringUTF8();
			this._className2IdMap.set(this._aniFileName[i], i);
		}

		let vAnimationID = 0;
		for (let vClassID=0; vClassID!==this._isActorPackAni.length; ++vClassID) {
			if (this._isActorPackAni[vClassID]) {
				this._animationIDToClassID.set(vAnimationID, vClassID);
				++vAnimationID;
			}
		}

		this._sceneCount = is.readJInt16();
		this._sceneNames = [];
		this._mapItemNames = [];
		this._buildItemNames = [];
		this._sceneFileNames = [];
		for (let i = 0; i < this._sceneCount; ++i) {
			this._sceneNames[i] = is.readStringUTF8();
			this._mapItemNames[i] = is.readStringUTF8();
			this._buildItemNames[i] = is.readStringUTF8();
			this._sceneFileNames[i] = is.readStringUTF8();
		}
		let imgCount = is.readJInt16();
		for (let i = 0; i < imgCount; ++i) {
			let imgName = is.readStringUTF8();
			if (is.readBool()) {
				this._additiveImgsMap.set(imgName, i);
			}
		}
	},

	getAniFileNameVec : function() {
		return this._aniFileName;
	},

	getAniFileNameByClassID : function(id) {
		if (id < 0 || id >= this._aniFileName.length) {
			return "__cantFind__";
		}
		return this._aniFileName[id];
	},

	getSceneFileNameBySceneID : function(sceneID) {
		if (sceneID < 0 || sceneID >= this._sceneNames.length) {
			return "";
		}
		return this._sceneNames[sceneID];
	},

	getClassIDByAnimationID : function(aniID) {
		return this._animationIDToClassID.get(aniID) || -1;
	},

	getClassIDByAniFileName : function(name) {
		return this._className2IdMap.get(name) || -1;
	},

	isImageNeedBlendAdditive : function(name) {
		return this._additiveImgsMap.has(name);
	},

	addImageMaskData : function(name, maskIndex) {
		this._imageMaskMap.set(name, maskIndex);
	},

	getImageMaskByName : function(name) {
		return this._imageMaskMap.get(name) || -1;
	},

	getDialogHeadAnimationID : function() {
		return this._dialogHeadAniID;
	},

	getClipAnimationTextureFullPath : function(name) {
		let ret = this._clipAnimationTextureFullPathMap.get(name);
		if (ret===undefined) {
			let path = ivy.GlobleConfig.getInstance().getAnimationImagePath(name);
			this._clipAnimationTextureFullPathMap.set(name, path);
			ret = path;
		}
		return ret;
	},

	isClipAnimationTextureFullPathExist : function(name) {
		return this._clipAnimationTextureFullPathMap.has(name);
	},
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////
	_imageMaskMap : new LLDictionary(),
	_systemFaceAniID : 0,
	_dialogHeadAniID : 0,
	_equipIconAniID : 0,
	_effectAniID : 0,

	_actorClassCount : 0,
	_isActorPackAni : [],
	_actorResType : [],
	_classAIIDs : [],
	_classFlags : [],
	_aniFileName : [],
	_className2IdMap : new LLDictionary(),

	_sceneCount : 0,
	_sceneNames : [],
	_mapItemNames : [],
	_buildItemNames : [],
	_sceneFileNames : [],

	_animationIDToClassID : new LLDictionary(),
	_additiveImgsMap : new LLDictionary(),

	_clipAnimationTextureFullPathMap : new LLDictionary(),
};

ivy.SceneCommonDataManager.ActorResType = {
	eNone           : -1,
	eSys            : 0,
	eDialogHead     : 1,
	eGoodsIcon      : 2,
	eEffect         : 3,
	eUI             : 4,
	eCG             : 5,
	eMainSityEffect : 6,
	eScriptEffect   : 7,
};